/**********************************************************************
* Filename: Clube.java
* Created: 2012/04/23
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.copaPaises.businessLayer;

import java.util.Set;
import java.util.HashSet;

public class Clube
{
	public static Set<Clube> allInstances = new HashSet<Clube>();
	
	private String nome;
	private Pais pais;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Clube()
	{
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param nome the nome to initialize
	* @param pais the pais to initialize
	**********************************************************************/
	public Clube(String nome, Pais pais)
	{
		this.nome = nome;
		this.pais = pais;
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the nome of the clube
	**********************************************************************/
	public String nome()
	{
		return nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param nome the nome to set
	**********************************************************************/
	public void setNome(String nome)
	{
		this.nome = nome;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Clube[*] <-> Pais[1]
	* @return the pais of the clube
	**********************************************************************/
	public Pais pais()
	{
		return pais;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Clube[*] <-> Pais[1]
	* @param pais the pais to set
	**********************************************************************/
	public void setPais(Pais pais)
	{
		this.pais = pais;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Clube[1] <-> Jogador[*]
	* @return the jogadores of the clube
	**********************************************************************/
	public Set<Jogador> jogadores()
	{
		Set<Jogador> result = new HashSet<Jogador>();
		for (Jogador x : Jogador.allInstances)
			if (x.clube()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Clube[1] <-> Jogador[*]
	* @param jogadores the jogadores to set
	**********************************************************************/
	public void setJogadores(Set<Jogador> jogadores)
	{
		for (Jogador x : jogadores)
			x.setClube(this);
	}
	
	
	/* (non-Javadoc)
	* @see java.lang.Object#toString()
	*/
	@Override
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Clube [nome=" + nome + ", pais=" + pais + "]\n";
	}
	
}
